package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportMsg;
import cn.stylefeng.guns.modular.transport.mapper.TransportMsgMapper;
import cn.stylefeng.guns.modular.transport.model.params.TransportMsgParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportMsgResult;
import  cn.stylefeng.guns.modular.transport.service.TransportMsgService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 运输信息表 服务实现类
 */
@Service
public class TransportMsgServiceImpl extends ServiceImpl<TransportMsgMapper, TransportMsg> implements TransportMsgService {

    @Override
    public void add(TransportMsgParam param){
        TransportMsg entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportMsgParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportMsgParam param){
        TransportMsg oldEntity = getOldEntity(param);
        TransportMsg newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportMsgResult findBySpec(TransportMsgParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<TransportMsgResult> findListBySpec(TransportMsgParam param,Long operateId){
        return this.baseMapper.findListBySpec(param,operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportMsgParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<TransportMsgResult> finddriverSigninPageBySpec2(TransportMsgParam param,String condition,Long operateId){
        return this.baseMapper.finddriverSigninPageBySpec2(param,condition, operateId);
    }

    @Override
    public LayuiPageInfo finddriverSigninPageBySpec(TransportMsgParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.finddriverSigninPageBySpec(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo finddriverSigninListPageBySpec(TransportMsgParam param,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.finddriverSigninListPageBySpec(pageContext, param, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportMsgParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportMsg getOldEntity(TransportMsgParam param) {
        return this.getById(getKey(param));
    }

    private TransportMsg getEntity(TransportMsgParam param) {
        TransportMsg entity = new TransportMsg();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public void deleteBySpec(TransportMsgParam msgParam) {
		this.baseMapper.deleteBySpec(msgParam);
	}

	@Override
	public TransportMsgResult findDcqdBySpec(TransportMsgParam param, Long operateId) {
		return this.baseMapper.findDcqdBySpec(param,operateId);
	}

    @Override
    public TransportMsgResult findDcqdByNumSpec(TransportMsgParam param) {
        return this.baseMapper.findDcqdByNumSpec(param);
    }


	@Override
	public void updateBySpec(TransportMsgParam msgParam) {
		this.baseMapper.updateBySpec(msgParam);
	}

	@Override
	public TransportMsgResult findZuixinBySpec(TransportMsgParam msgParam) {
		return this.baseMapper.findZuixinBySpec(msgParam);
	}

	@Override
	public Integer countqiandaocheci(TransportMsgParam msgParam,Long operateId) {
		return this.baseMapper.countqiandaocheci(msgParam, operateId);
	}

}
